package com.swak.boot.config.job;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.swak.annotation.Flux;
import com.swak.job.aspect.DelayJobEventAspect;
import com.swak.job.manager.JobManagerImpl;
import com.swak.job.manager.jobs.EventJob;
import com.swak.job.manager.jobs.RetryJob;
import com.swak.job.storage.StorageService;

/**
 * 管理端配置;
 * 
 * @author 618lf
 */
@Configuration
@ConditionalOnBean(StorageService.class)
@ConditionalOnProperty(prefix = "spring.job.mamager", name = "enable", matchIfMissing = true)
public class JobManagerAutoConfiguration {

	/**
	 * 配置任务事件
	 * 
	 * @return
	 */
	@Bean
	@Flux(EventJob.class)
	public EventJob EventJob() {
		return new EventJob();
	}

	/**
	 * 配置重试任务
	 * 
	 * @return
	 */
	@Bean
	@Flux(RetryJob.class)
	public RetryJob RetryJob() {
		return new RetryJob();
	}

	/**
	 * 配置任务管理器
	 * 
	 * @return
	 */
	@Bean
	@Flux(JobManagerImpl.class)
	public JobManagerImpl JobManager() {
		return new JobManagerImpl();
	}

	/**
	 * 定义延迟任务
	 * 
	 * @return
	 */
	@Bean
	public DelayJobEventAspect delayJobEventAspect() {
		return new DelayJobEventAspect();
	}
}